﻿//使用FAST算子进行角点检测与匹配

#include "pch.h"
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/xfeatures2d/nonfree.hpp>

using namespace cv;
using namespace std;

int main()
{
	Mat church = imread("E:\\VC_project\\figure\\church.jpg");
	Mat chess = imread("E:\\VC_project\\figure\\chess.jpg");
	double t = getTickCount();//当前滴答数
	if (church.empty()||chess.empty())
	{
		cout << "图片读取失败！" << endl;
		return -1;
	}
	Mat church90;
	flip(church, church90, 0);//将图片旋转90度

	//对图像进行灰度处理
	Mat graychess,graychurch,graychurch90;
	cvtColor(chess, graychess, COLOR_BGR2GRAY);
	cvtColor(church, graychurch, COLOR_BGR2GRAY);
	
	//创建FAST算子
	vector<KeyPoint>keypoints1, keypoints2;

	Ptr<FeatureDetector>fastChurch = cv::FastFeatureDetector::create(60); //设置检测阈值
	Ptr<FeatureDetector>fastChess = cv::FastFeatureDetector::create(52);
	
	//检测角点
	fastChurch->detect(graychurch, keypoints1);
	fastChess->detect(graychess, keypoints2);

	//在原图中绘制角点
	drawKeypoints(church, keypoints1, church, Scalar(255, 255, 255), DrawMatchesFlags::DRAW_OVER_OUTIMG);
	drawKeypoints(chess, keypoints2, chess, Scalar(0, 0, 255), DrawMatchesFlags::DRAW_OVER_OUTIMG);
	
	t = ((double)getTickCount() - t) / getTickFrequency();
	cout << "算法用时：" << t << "秒" << endl;// t=0.064s

	imshow("FAST-Church角点检测", church);
	imshow("FAST-Chess角点检测", chess);
	
	waitKey();


}

